#include"CommandArrays.h"
unsigned char gModuleInf[]={0xAA,0x00,0x03,0x00,0x01,0x00,0x04,0xDD};
unsigned char SingleID[]={0xAA,0x00,0x22,0x00,0x00,0x22,0xDD};
unsigned char MultiID[]={0xAA,0x00,0x27,0x00,0x03,0x22,0x27,0x10,0x83,0xDD};
unsigned char StopMulti[]={0xAA,0x00,0x28,0x00,0x00,0x28,0xDD};
unsigned char sSelectPM[]={0xAA,0x00,0x0C,0x00,0x13,0x01,0x00,0x00,0x00,0x20,0x60,0x00,0x30,0x75,0x1F,0xEB,0x70,0x5C,0x59,0x04,0xE3,0xD5,0x0D,0x70,0xAD,0xDD};//设置 Select 参数指令
unsigned char gSelectPM[]={0xAA,0x00,0x0B,0x00,0x00,0x0B,0xDD};//.获取 Select 参数
unsigned char sSelectMode[]={0xAA,0x00,0x12,0x00,0x01,0x01,0x14,0xDD};//设置 Select 模式
unsigned char ReadData[]={0xAA,0x00,0x39,0x00,0x09,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x08,0x4D,0xDD};//7~10位全为0则不发送密码
unsigned char WriteData[]={0xAA,0x00,0x49,0x00,0x0D,0x00,0x00,0xFF,0xFF,0x03,0x00,0x00,0x00,0x02,0x12,0x34,0x56,0x78,0x6D,0xDD};
unsigned char LockUnlock[]={0xAA,0x00,0x82,0x00,0x07,0x00,0x00,0xFF,0xFF,0x02,0x00,0x80,0x09,0xDD};
unsigned char Kill[]={0xAA,0x00,0x65,0x00,0x04,0x00,0x00,0xFF,0xFF,0x67,0xDD};
unsigned char sBaudRate[]={0xAA,0x00,0x11,0x00,0x02,0x00,0xC0,0xD3,0xDD};
unsigned char gQueryPM[]={0xAA,0x00,0x0D,0x00,0x00,0x0D,0xDD};//获取query参数
unsigned char sQueryPM[]={0xAA,0x00,0x0E,0x00,0x02,0x10,0x20,0x40,0xDD};//设置query参数
unsigned char sRegion[]={0xAA,0x00,0x07,0x00,0x01,0x01,0x09,0xDD};
unsigned char gRegion[]={0xAA,0x00,0x08,0x00,0x00,0x08,0xDD};
unsigned char sWorkChannel[]={0xAA,0x00,0xAB,0x00,0x01,0x01,0xAC,0xDD};
unsigned char gWorkChannel[]={0xAA,0x00,0xAA,0x00,0x00,0xAA,0xDD};
unsigned char sAutotiaopin[]={0xAA,0x00,0xAD,0x00,0x01,0xFF,0xAD,0xDD};//设置自动跳频
unsigned char iWorkChannel[]={0xAA,0x00,0xA9,0x00,0x06,0x05,0x01,0x02,0x03,0x04,0x05,0xC3,0xDD};//插入 i=insert
unsigned char gPower[]={0xAA,0x00,0xB7,0x00,0x00,0xB7,0xDD};
unsigned char sPower[]={0xAA,0x00,0xB6,0x00,0x02,0x07,0xD0,0x28,0x8F,0xDD};
unsigned char sCW[]={0xAA,0x00,0xB0,0x00,0x01,0xFF,0xB0,0xDD};//设置连续载波
unsigned char gModernPM[]={0xAA,0x00,0xF1,0x00,0x00,0xF1,0xDD};
unsigned char sModernPM[]={0xAA,0x00,0xF0,0x00,0x04,0x03,0x06,0x01,0xB0,0xAE,0xDD};
unsigned char scanJammer[]={0xAA,0x00,0xF2,0x00,0x00,0xF2,0xDD};//.测试射频输入端阻塞信号
unsigned char testRSSI[]={0xAA,0x00,0xF3,0x00,0x00,0xF3,0xDD};//.测试信道RSSI
unsigned char IOControl[]={0xAA,0x01,0x1A,0x00,0x03,0x00,0x04,0x01,0x22,0xDD};
unsigned char SleepMode[]={0xAA,0x00,0x17,0x00,0x00,0x17,0xDD};
unsigned char sAutoSleep[]={0xAA,0x00,0x1D,0x00,0x01,0x02,0x20,0xDD};//设置多久自动休眠
unsigned char ILDEMode[]={0xAA,0x01,0x04,0x00,0x03,0x01,0x01,0x03,0x0C,0xDD};
unsigned char ReadProtest[]={0xAA,0x00,0xE1,0x00,0x05,0x00,0x00,0xFF,0xFF,0x00,0xE4,0xDD};//NXP ReadProtect/Reset ReadProtect 指令
unsigned char NXP_Change_EAS[]={0xAA,0x00,0xE3,0x00,0x05,0x00,0x00,0xFF,0xFF,0x01,0xE7,0xDD};
unsigned char NXP_EAS_Alarm[]={0xAA,0x00,0xE4,0x00,0x00,0xE4,0xDD};
unsigned char NXP_ChangeConfig[]={0xAA,0x00,0xE0,0x00,0x06,0x00,0x00,0xFF,0xFF,0x00,0x00,0xE4,0xDD};
unsigned char Impinj_Monza_QT[]={0xAA,0x00,0xE5,0x00,0x08,0x00,0x00,0xFF,0xFF,0x01,0x01,0x40,0x00,0x2D,0xDD};
unsigned char BlockPermalock[]={0xAA,0x00,0xD3,0x00,0x0B,0x00,0x00,0xFF,0xFF,0x01,0x03,0x00,0x00,0x01,0x07,0x00,0xE8,0xDD};
void getModuleInf()
{
  inputCommand(gModuleInf,sizeof(gModuleInf));
}
void doSingleID()
{
  inputCommand(SingleID,sizeof(SingleID));
}
void doMultiID(int n)//n为轮询次数，范围0-65535
{
  if(n<1)goto case1;
  else{
  int a,b;
  a=n/100;
  b=n-a*100;
  MultiID[6]=a;MultiID[7]=b;}
  case1:
  inputCommand(MultiID,sizeof(MultiID));
}
void doStopMulti()
{
  inputCommand(StopMulti,sizeof(StopMulti));
}
void setSelectPM(int n[])
{
  for(int i=0;i<12;i++)
  {
    sSelectPM[12+i]=n[i];
  }
  inputCommand(sSelectPM,sizeof(sSelectPM));
}
void getSelectPM()
{
  inputCommand(gSelectPM,sizeof(gSelectPM));
}
void setSelectMode()
{
  inputCommand(sSelectMode,sizeof(sSelectMode));
}
void doReadData()//默认读USER区
{
  inputCommand(ReadData,sizeof(ReadData));
}
void doWriteData()
{
  inputCommand(WriteData,sizeof(WriteData));
}
void doLockUnlock()
{
  inputCommand(LockUnlock,sizeof(LockUnlock));
}
void doKill()
{
  inputCommand(Kill,sizeof(Kill));
}
void setBaudRate(int n)
{
  if(n<1)goto case1;
  else{
  int a,b;
  a=n/100;
  b=n-a*100;
  sBaudRate[5]=a;sBaudRate[6]=b;}
  case1:
  inputCommand(sBaudRate,sizeof(sBaudRate));
}
void getQueryPM()
{
  inputCommand(gQueryPM,sizeof(gQueryPM));
}
void setQueryPM(int n)
{
  if(n<1)goto case1;
  else{
  int a,b;
  a=n/100;
  b=n-a*100;
  sQueryPM[5]=a;sQueryPM[6]=b;}
  case1:
  inputCommand(sQueryPM,sizeof(sQueryPM));
}
/*
中国 900MHz 01
中国 800MHz 04
美国 02
欧洲 03
韩国 06
 */
void setRegion(int n)
{
  sRegion[4]=n;
  inputCommand(sRegion,sizeof(sRegion));
}
void getRegion()
{
  inputCommand(gRegion,sizeof(gRegion));
}
/*void setWorkChannel()
{
  inputCommand(sWorkChannel,sizeof(SingleID));
}*/
void getWorkChannel()
{
  inputCommand(gWorkChannel,sizeof(gWorkChannel));
}
void setAutotiaopin(int n)
{
  if(n==0)sAutotiaopin[5]=0x00;
  else sAutotiaopin[5]=0xFF;
  inputCommand(StopMulti,sizeof(StopMulti));
}
/*void inputWorkChannel()
{
  inputCommand(iWorkChannel,sizeof(StopMulti));
}*/
void getPower()
{
  inputCommand(gPower,sizeof(gPower));
}
void setPower()//只能输入十六进制
{
  /*if(n<1)goto case1;
  else{
  int a,b;
  a=n/100;
  b=n-a*100;
  sQueryPM[5]=a;sQueryPM[6]=b;}
  case1:*/
  inputCommand(sPower,sizeof(sPower));
}
void setCW(int n)
{
  if(n==0)sCW[5]=0x00;
  else sCW[5]=0xFF;
  inputCommand(sCW,sizeof(sCW));
}
void getModernPM()
{
  inputCommand(gModernPM,sizeof(gModernPM));
}
//a=混频器增益 b=Mixer_G中频放大器增益 c=IF_G信号解调阈值 Thrd:
void setModernPM(int a,int b,int c)
{
  sModernPM[5]=a;
  sModernPM[6]=b;
  int c1,c2;
  c1=c/100;
  c2=c-c1*100;
  sModernPM[7]=c1;
  sModernPM[8]=c2;
  inputCommand(sModernPM,sizeof(sModernPM));
}
void doscanJammer()
{
  inputCommand(scanJammer,sizeof(scanJammer));
}
void dotestRSSI()
{
  inputCommand(testRSSI,sizeof(testRSSI));
}
/*void IOControl()
{
  inputCommand(IOControl,sizeof(IOControl));
}*/
void doSleepMode()
{
  inputCommand(SleepMode,sizeof(SleepMode));
}
void setAutoSleep(int minute)//如果 设置minute=2  则2 分钟无操作之后休眠，范围 1~30 分钟，0x00 代表不自动休眠
{
  sAutoSleep[5]=minute;
  inputCommand(sAutoSleep,sizeof(sAutoSleep));
}
void doILDEMode(int n,int minute)//IDLE 模式下除了数字部分和通信接口，其余所有模拟和射频部分电源均被关闭，以减少不工作情况下的功耗
{
  if(n==0)ILDEMode[5]=0x00;
  else ILDEMode[5]=0x01;
  ILDEMode[7]=minute;
  inputCommand(ILDEMode,sizeof(ILDEMode));
}
void doNXP_Change_EAS(int n,int ap[])//0x00 代表执行 ReadProtect，0x01 代表执行 Reset ReadProtect)
{
  if(n==0)NXP_Change_EAS[9]=0x00;
  else NXP_Change_EAS[9]=0x01;
  for(int i=0;i<5;i++)
  {
    NXP_Change_EAS[i+5]=ap[i];
  }
  inputCommand(NXP_Change_EAS,sizeof(NXP_Change_EAS));
}/*
void doStopMulti()
{
  inputCommand(StopMulti,sizeof(StopMulti));
}
void doStopMulti()
{
  inputCommand(StopMulti,sizeof(StopMulti));
}
void doStopMulti()
{
  inputCommand(StopMulti,sizeof(StopMulti));
}
void doStopMulti()
{
  inputCommand(StopMulti,sizeof(StopMulti));
}
*/

void inputCommand(unsigned char a[],int n)
{
  for(int i=0;i<n;i++)
  RFID.write(a[i]);
}
